/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package our.gui;

import java.awt.KeyboardFocusManager;

/**
 *
 * @author keysman
 */
public class ourList extends javax.swing.JList {
    // Definisco la classe che possiede le funzioni comuni a tutti gli oggetti a video
    public our.gui.commonObjectClass SETTINGS = new our.gui.commonObjectClass();

    public ourList() {
        setFont(SETTINGS.getLabelFont());
        // Imposto l'altezza dell'oggetto
        setSize(getWidth(), SETTINGS.getOurHeight());
        addKeyListener(new java.awt.event.KeyAdapter() {
            @Override
            public void keyPressed(java.awt.event.KeyEvent evt) {
                int iSel = getSelectedIndex();
                int iNumElem = getModel().getSize();
                if(evt.getKeyCode() == java.awt.event.KeyEvent.VK_ENTER)
                {
                    KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
                    kfm.focusNextComponent();
                }
                if((evt.getKeyCode() == java.awt.event.KeyEvent.VK_UP) && (iSel<=0))
                {
                    KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
                    kfm.focusPreviousComponent();
                }
                if( (evt.getKeyCode() == java.awt.event.KeyEvent.VK_DOWN) && (iSel==iNumElem-1) )
                {
                    KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
                    kfm.focusNextComponent();
                }
            }
        });
    }


    /**
     * Questa funzione disabilita la gestione del mouse del campo ourTextField e in caso di MOUSE_CLICKED richiama
     * la funzione di gestione del parent: ourTextField
     * @param e
     */
    @Override
    protected void processMouseEvent(java.awt.event.MouseEvent e)
    {
        if(SETTINGS.getOurForm()!=null)
        {
            if(e.paramString().indexOf("MOUSE_CLICKED")>=0)
            {
                SETTINGS.getOurForm().clickOnComponent(this);
            }
            e.consume();
        } else if(e.paramString().indexOf("MOUSE_CLICKED")>=0) {
            requestFocus();
            super.processMouseEvent(e);
        }
    }



}
